<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title th:text="${title}"></title>
    <meta name="ctx" th:content="${#httpServletRequest.getContextPath()}"/>
	<link rel="shortcut icon" th:href="@{/img/favicon.ico}" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{/css/admin/base-v2.css}">
    <link rel="stylesheet" th:href="@{/css/wlfb-font/css/iconfont.css}">
    <link rel="stylesheet" th:href="@{/css/admin/app.css}">
</head>

<body>
<div class="app">
    <div class="app-header">
        <div class="logo" th:switch="${type}">
            <span th:case="1"><img th:src="${company.companyLogoUrl}" alt=""></span>
            <span th:case="0"><img th:src="@{/img/logo.png}" alt=""></span>
        </div>
        <div class="title" th:switch="${type}">
            <span th:case="1" th:text="${company.companyName}"></span>
            <span th:case="0" th:text="创客管理平台"></span>
        </div>
        <a th:href="@{/web/logout}">
            <div class="logout">
                <i class="icon xcfont xc-logout"></i><span>退出登录</span>
            </div>
        </a>

        <div class="user">
            <img th:src="@{/img/portrait.svg}" alt=""> <span th:text="${userName}"></span>
        </div>
    </div>
    <div class="app-container">
        <div class="app-aside">
            <div class="menu-switch">
                <i class="icon xcfont xc-right"> </i>
            </div>
            <div class="menu-list">
            </div>
        </div>

        <div class="mini-sub-menu">

        </div>

        <div class="app-main">
            <!-- <div class="app-page-header">
                <div class="app-breadcrumb">
                    <a>通用模块</a>
                    <a>列表</a>
                </div>
            </div> -->
            <!-- 初始页面地址 -->
            <iframe src="" frameborder="0"></iframe>
        </div>
    </div>
</div>

<script th:src="@{/lib/jquery.min.js}"></script>
<script th:src="@{/js/admin/index.js}"></script>
<script type="text/javascript" th:inline="javascript">
    //获取context path
    var context = $("meta[name='ctx']").attr("content") || '';

    $(function () {
        //初始化菜单
        // var menudata = null;
        var url = context + "/module/listMenuModule";
        $.ajax({
            type: "POST",
            url: url,
            success: function (obj) {
                var code = obj.code;
                if (code == 0) {
                    parseMenu(obj.data, context);
                }
            }
        })
    })

    //解析函数
    function parseMenu(arr, ctx) {

        var homeUrl = '';
        if (arr.length != 0) {

            function pp(arr, pid) {

                for (var i = 0; i < arr.length; i++) {

                    var menuinfo = arr[i];

                    var href = menuinfo.url;

                    if(href && href == '/ckWeb/goHome' && isBlank(homeUrl)){
                        homeUrl = ctx + href;
                    } else if(href && href == '/cpweb/goCpHome' && isBlank(homeUrl)){
                        homeUrl = ctx + href;
                    }

                    if (menuinfo.label && menuinfo.moduleId) {

                        //这里可以写菜单的样式结构...
                        if (!pid) {

                            var $menuitem = $('<div class="menu-group">' +
                                '                    <a class="menu-item" href="' + (href ? ctx + href : '') + '"  id="' + menuinfo.moduleId + '">' +
                                // '                    <a class="menu-item"  id="' + menuinfo.moduleId + '">' +
                                '                        <i class="icon xcfont xc-' + menuinfo.icon + '"></i>' +
                                '                        <div class="title">' + menuinfo.label + '</div>' +
                                '                        <div class="arrow xcfont ' + (menuinfo.children.length > 0 ? 'xc-right1' : '') + '"></div>' +
                                '                    </a>' +
                                // '                    <ul style="" id=""></ul>' +
                                '                </div>');
                            $('.menu-list').append($menuitem)
                        } else {

                            var $menuitem = $(
                                '            <div class="menu-group">' +
                                '                <a class="menu-item" href="' + (href ? ctx + href : '') + '" id="' + menuinfo.moduleId + '">' +
                                // '                <a class="menu-item" id="' + menuinfo.moduleId + '">' +
                                '                    <div class="title">' + menuinfo.label + '</div>' +
                                '                    <div class="arrow xcfont ' + (menuinfo.children.length > 0 ? 'xc-right1' : '') + '"></div>' +
                                '                </a>' +
                                '            </div>'
                                )
                            ;

                            if ($('#' + pid).siblings('ul').length > 0) {
                                $('#' + pid).siblings('ul').append($menuitem)
                            } else {
                                $('#' + pid).parent().append('<ul style="" id=""></ul>');
                                $('#' + pid).siblings('ul').append($menuitem)
                            }

                        }

                        pp(menuinfo.children, menuinfo.moduleId);
                    } else {
                        //这里可以写菜单的样式结构...
                    }
                }
            }

            pp(arr, null);
            $('.menu-item').click(function () {
                var lable = $(this).find('div[class="title"]').text();
                console.log(lable);
            })
        }
        if(!isBlank(homeUrl)){
            $("iframe").attr("src",homeUrl);
        }
    }

    function isBlank(param) {
        if (null == param) {
            return true;
        }
        if ('' === param) {
            return true;
        }
        if (undefined === param) {
            return true;
        }
        if ('undefined' === param) {
            return true;
        }
        return false;
    }
</script>

</body>

</html>